<template>
  <view class="goods-item">
    <view class="goods-item-left">
      <radio :checked="item.goods_state" color="#C00000" v-if="showRadio" @click="radioChange"></radio>
      <image :src="item.goods_small_logo || defaultImg" class="goods-img"></image>
    </view>
    <view class="goods-item-right">
      <view class="goods-title">{{item.goods_name}}</view>
      <view class="goods-right-bottom">
        <view class="goods-price">￥ {{item.goods_price | tofixed}}</view>
        <uni-number-box :min="1" :value="item.goods_count" v-if="showNum" @change="numChange"></uni-number-box>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name:"my-goods",
    props: {
      item: {
        type: Object,
        default: {}
      },
      showRadio: {
        type: Boolean,
        default: false
      },
      showNum: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        defaultImg: 'https://img1.baidu.com/it/u=407852637,3650486136&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500',
      };
    },
    filters: {
      tofixed(num) {
        return Number(num).toFixed(2)
      }
    },
    methods: {
      // 勾选状态
      radioChange() {
        this.$emit('radioChangeHandler', {
          goods_id: this.item.goods_id,
          goods_state: this.item.goods_state
        })
      },
    
      // 商品数量改变
      numChange(newValue) {
        this.$emit('numChangeHandler', {
          goods_id: this.item.goods_id,
          goods_count:newValue
        })
      }
      
    }
  }
</script>

<style lang="scss">
.goods-item {
  padding: 20rpx;
  display: flex;
  border-bottom: 1px solid #efefef;
  .goods-item-left {
    margin-right: 10rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .goods-img {
      width: 200rpx;
      height: 200rpx;
      display: block;
    }
  }
  .goods-item-right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10rpx;
    .goods-title {
      font-size: 24rpx;
    }
    .goods-right-bottom {
      display: flex;
      justify-content: space-between;
      .goods-price {
        color: #C00000;
        font-size: 32rpx;
      }
    }
  }
}

</style>